<?php
class Thesis extends CI_Controller{
	function __construct(){
		parent::__construct();
	}
	
	function index(){
		if ($this->session->userdata('logged_in')==false){
			redirect('/login');
		}
	}
	
	//view topic detail
	function viewtopic(){
		if ($this->session->userdata('logged_in')==false){
			redirect('/login');
		}
		
		$topicId = $this->uri->segment(3);
		$this->load->model('thesismodel');
		$data['rows']= $this->thesismodel->searchById($topicId);
		$data['title'] = 'Topic';
		$this->load->model('liststudent');
		
		//check by topic id if student already erolled
		if ($this->liststudent->check($topicId))
			$data['checkStudent'] = true;
		else 
			$data['checkStudent'] = false;
			
		$this->load->model('thesismodel');
		//check by topic id if the topic belongs to the teacher
		if ($this->thesismodel->checkOwner($topicId))
			$data['checkTeacher'] = true;
		else
			$data['checkTeacher'] = false;
		$this->load->view('thesisView',$data);
	}
}
?>